package cn.xclink.kernel.shiro;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import cn.xclink.common.Constants;
import cn.xclink.kernel.service.UserService;


public class SysUserFilter extends PathMatchingFilter {

    @Autowired
    private UserService userService;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        String account = (String)SecurityUtils.getSubject().getPrincipal().toString();
        request.setAttribute(Constants.CURRENT_USER, userService.findUserByAccount(account));
        return true;
    }
}
